# This is a sample Python script.

# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.

import os
import json


def print_hi(name):
    # Use a breakpoint in the code line below to debug your script.
    print(f'Hi, {name}')  # Press Ctrl+F8 to toggle the breakpoint.


def generate_range(file_full_path, file_name):
    range = {}
    with open(file_full_path, 'r') as f:
        content = f.read()
        hand_array = content.split(',')
        for hand_item in hand_array:
            if hand_item.find('[/') == -1:
                range[hand_item] = 100
            else:
                index1 = hand_item.find(']')
                index2 = hand_item.find('[/')
                hand = hand_item[index1 + 1: index2]
                percent = float(hand_item[1:index1])
                range[hand] = percent

    with open('range/' + file_name[:-4] + '.json', 'w') as fJson:
        fJson.write(json.dumps(range))


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    for parent, dirs, file_names in os.walk('origin'):
        for file_name in file_names:
            file_full_path = os.path.join(parent, file_name)
            generate_range(file_full_path, file_name)

    print_hi('PyCharm')

# See PyCharm help at https://www.jetbrains.com/help/pycharm/
